package ch10_thread.thread;


/**
 * 对象锁形式-方法修饰符，锁对象默认是this
 *
 * @author guodd
 * @version 1.0 use jdk 1.8
 */
public class Synchronized04 implements Runnable {
    public static void main(String[] args) {
        Synchronized04 syn = new Synchronized04();
        Thread t01 = new Thread(syn);
        Thread t02 = new Thread(syn);
        t01.start();
        t02.start();
    }

    @Override
    public void run() {
        methodOpt();
    }

    private synchronized void methodOpt() {
        System.out.println("我是对象锁的方法修饰符，线程：" + Thread.currentThread().getName());
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread().getName() + "线程结束");
    }
}
